package com.sptpc.hello.controller;

import com.sptpc.hello.modei.Category;
import com.sptpc.hello.modei.Drink;
import com.sptpc.hello.service.ICategoryService;
import com.sptpc.hello.service.IDrinkService;
import org.joda.money.CurrencyUnit;
import org.joda.money.Money;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class RouterController {

    @Autowired
    public IDrinkService drinkService;
    @Autowired
    public ICategoryService categoryService;

    //首页（登录）路由
    @GetMapping("/")
    public String Index(){
        return "manage/login";
    }
    //后台首页路由
    @GetMapping("/manage/index")
    public String adminIndex(){
        return "manage/index";
    }
    //后台欢迎页面路由
    @GetMapping("/manage/welcome")
    public String welcome(){
        return "manage/welcome";
    }
    //饮品管理首页路由
    @GetMapping("/menu/drink")
    public String drinkIndex(){
        return "drink/index";
    }
    //饮品添加管理路由
    @GetMapping("/drink/addform")
    public String drinkaddFrom(){
        return "drink/add";
    }
    //饮品修改页路由
    // get /drink/updateform?id=13
    @GetMapping("/drink/updateform")
    public ModelAndView drinkupdateFrom(@RequestParam Integer id){
        ModelAndView mv = new ModelAndView("drink/edit");
        // TODO: 从数据库通过id查询出对应饮品信息
//        Drink build = Drink.builder().id(13)
//                .name("茉莉花茶")
//                .price(Money.of(CurrencyUnit.of("CNY"),12.00))
//                .build();

        Drink drink = drinkService.getDrinkById(id);
        mv.addObject("data",drink);
        return mv;
    }

    //分类管理首页路由
    @GetMapping("/menu/category")
    public String categoryIndex(){
        return "category/index";
    }

    //分类添加路由
    @GetMapping("/category/addform")
    public String categoryAddFrom(){
        return "category/add";
    }
    //分类修改路由
    //get /category/updateform?id=
    @GetMapping("/category/updateform")
    public ModelAndView categoryupdateFrom(@RequestParam Integer id){
        ModelAndView mv = new ModelAndView("category/edit");
        Category category = categoryService.getCategoryById(id);
        mv.addObject("data",category);
        return mv;
    }

}
